package concesionaria;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.ConsoleHandler;

/**
 *
 * @author Guillermo
 * @author Matias
 * 
 */
public class InstAuto extends Auto {

    private int auto;
    private String patente;
    private String chasis;
    private String motor;
    private String color;

    public InstAuto() {
    }

    public boolean Inicializar(int auto, String patente, String chasis, String motor, String color) {
        try {
            String SQL = "select a.marca , a.modelo, a.precio_ctdo from auto a where a.`ID`= " + auto;
            Statement stmt;
            stmt = DBCon.getConexion().createStatement();
            ResultSet rs;
            rs = stmt.executeQuery(SQL);
            rs.next();
            setMarca(rs.getString("marca"));
            setModelo(rs.getString("modelo"));
            setPrecioContado(rs.getFloat("precio_ctdo"));

        } catch (SQLException e) {
            System.out.print("Error en SQL: " + e.getMessage());
        }
        this.auto=auto;
        this.chasis = chasis;
        this.patente = patente;
        this.motor = motor;
        this.color = color;
        return true;
    }

    public int AltaIAuto() {
        int id=-1;
        try {
            String SQL1 = "select count(*) from auto_inst";
            Statement stmt;
            stmt = DBCon.getConexion().createStatement();
            ResultSet rs = stmt.executeQuery(SQL1);
            while (rs.next()) {
                id = rs.getInt(1) + 1;
            }
            id++;
            String SQL2 = "INSERT INTO concesionaria.auto_inst (`ID`,`ID_auto`, patente, motor, chasis, color) "
                    + "VALUES ("+id+", "+this.auto+", '"+patente+"', '"+motor+"', '"+chasis+"', '"+color+"')";

            stmt = DBCon.getConexion().createStatement();
            stmt.executeUpdate(SQL2);
        } catch (SQLException e1) {
            System.out.println(e1.getMessage());
            return 0;
        }
        return id;
    
    }

    public void setPatente(String patente) {
        this.patente = patente;
    }

    public String getPatente() {
        return this.patente;
    }

    public void setChasis(String chasis) {
        this.chasis = chasis;
    }

    public String getChasis() {
        return this.chasis;
    }

    public void setMotor(String motor) {
        this.motor = motor;
    }

    public String getMotor() {
        return this.motor;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getColor() {
        return this.color;
    }
}
